package cn.botter.subject.application.controller;

import cn.botter.subject.common.utils.LoginUtil;
import cn.botter.subject.common.entity.PageResult;
import cn.botter.subject.infra.basic.entity.SubjectInfoES;
import cn.botter.subject.infra.basic.service.SubjectESService;
import cn.botter.subject.infra.entity.UserInfo;
import cn.botter.subject.infra.rpc.UserRpc;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

@RestController
@RequestMapping("/subject/category")
@Slf4j
public class TestFeignController {

    @Resource
    private UserRpc userRpc;
    @Resource
    private SubjectESService subjectESService;
    @GetMapping("testFeign")
    public void testFeign() {
        String loginId = LoginUtil.getLoginId("loginId");
        UserInfo userInfo = userRpc.getUserInfo(loginId);
        log.info("testFeign.userInfo:{}", userInfo);
    }

    @RequestMapping("testQueryByKeyWord")
    public PageResult<SubjectInfoES> testQueryByKeyWord() {
        SubjectInfoES subjectInfoES = new SubjectInfoES();
        subjectInfoES.setKeyWord("redis");
        PageResult<SubjectInfoES> subjectInfoESPageResult = subjectESService.querySubjectList(subjectInfoES);
        if (log.isInfoEnabled()) {
            log.info("subjectInfoESPageResult:{}", subjectInfoESPageResult);
        }
        return subjectInfoESPageResult;
    }

}
